import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import prismjs from 'vite-plugin-prismjs'
import Compression from 'vite-plugin-compression'
import OptimizationPersist from 'vite-plugin-optimize-persist'
import PkgConfig from 'vite-plugin-package-config' 
import { resolve } from 'path'

export default defineConfig({
  plugins: [
    vue(),
    PkgConfig(),
    OptimizationPersist(),
    Components({
      resolvers: [NaiveUiResolver()],
    }),
    Compression({
      filter: /.(js|mjs|json|css)$/i, // 选择哪些文件要压缩
      ext: '.gz',
      algorithm: 'gzip',
      deleteOriginFile: true,
    }),
    prismjs({
      languages: 'all',
    }),
  ],
  server: {
    host: true,
    open: false,
    port: 666,
    strictPort: true,
    hmr: {
      overlay: false,
    },
  },
  resolve: {
    alias: [
      { find: '@', replacement: resolve(__dirname, 'src') },
      { find: '@c', replacement: resolve(__dirname, 'src/components') },
      { find: '@api', replacement: resolve(__dirname, 'src/axios/api') },
    ],
  },
  build: {
    assetsDir: './static',
    reportCompressedSize: false,
    cssTarget: 'chrome61',
    minify: 'terser',
    brotliSize: false,
    compress: {
      // warnings: false,
      drop_console: true,  //打包去掉console
      drop_debugger: true, //打包去掉debugger
      pure_funcs: ['console.log'],
    },
    output: {
      comments: true,// 打包去掉注释内容
    },
    rollupOptions: {
      output: {
        manualChunks: {
          // 拆分代码，分包，配置完后自动按需加载。
          vue: ['vue', 'vue-router'],
          axios: ['axios'],
          pinia: ['pinia'],
        },
      },
    },
  },
})
